refactor(protect): stack-adapter architecture for the protect scaffolder#81
Merged
Merged
Conversation
Reorganize `patchstack-connect protect` around a per-stack adapter interface so more
builders/frameworks can be auto-wired, and so an unmatched stack escalates instead of
silently skipping (the "never manual install" direction).
- src/protect/install/{index,types,util}.ts + adapters/tanstack-supabase.ts
- `Adapter` = { name, label, detect(cwd), wire(cwd, opts) }; the current TanStack Start +
Supabase logic (scaffold / bake UUID / patch client + start / reconcile blocks) is now
adapter #1, unchanged behaviorally.
- index.ts registry picks the first matching adapter; `runProtect` returns a structured
ProtectResult (`wired` + adapter + changed files, or `unsupported` + supported list).
- **No silent skip:** an unmatched stack now logs a loud, actionable message (guard engine
is stack-agnostic; needs a new adapter or agent-assisted install) — the seam for the
agent-fallback track.
- Deleted the monolithic src/protect/install.ts; cli.ts + tests repointed.
Templates unchanged (still src/protect/templates → dist/protect/templates). +2 tests
(wired-result contract, escalation). 443 tests pass, typecheck + build clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Well-structured adapter introduction improves scaffold maintainability and clarity. 🎯 Quality: 100% Elite · 📦 Size: Medium 📈 This month: Your 33rd PR — above team average · Averaging Excellent |
Contributor
Author
|
/review |
This was referenced Jul 15, 2026
mariojgt
approved these changes
Jul 15, 2026
patchstackdave
added a commit
that referenced
this pull request
Jul 15, 2026
Two new per-stack adapters on the #81 interface, dependency-free (anchor + #region markers, same approach as tanstack — no AST parser, keeping dependencies:{}). - Express: detect (express dep + an `= express()` site), scaffold the generic guard, and wire `app.use(patchstackMiddleware)` right after the app is created (import + region-marked insert, idempotent). verify() checks the guard is scaffolded + the middleware is wired. - Next.js: detect (next dep); scaffold `middleware.ts` (+ co-located patchstack.rules.json) from a new template running the request-phase guard as edge middleware. An EXISTING middleware is never overwritten — we scaffold the rules and print a plan instead. verify() checks the managed middleware + rules are present. - Registered in the orchestrator (tanstack → next → express → generic fallback); AGENT-INSTALL lists the newly auto-wired stacks. +4 tests. 451 tests pass, typecheck + build clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
patchstackdave
added a commit
that referenced
this pull request
Jul 15, 2026
Two new per-stack adapters on the #81 interface, dependency-free (anchor + #region markers, same approach as tanstack — no AST parser, keeping dependencies:{}). - Express: detect (express dep + an `= express()` site), scaffold the generic guard, and wire `app.use(patchstackMiddleware)` right after the app is created (import + region-marked insert, idempotent). verify() checks the guard is scaffolded + the middleware is wired. - Next.js: detect (next dep); scaffold `middleware.ts` (+ co-located patchstack.rules.json) from a new template running the request-phase guard as edge middleware. An EXISTING middleware is never overwritten — we scaffold the rules and print a plan instead. verify() checks the managed middleware + rules are present. - Registered in the orchestrator (tanstack → next → express → generic fallback); AGENT-INSTALL lists the newly auto-wired stacks. +4 tests. 451 tests pass, typecheck + build clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
patchstackdave
added a commit
that referenced
this pull request
Jul 15, 2026
) * feat(protect): Express + Next.js adapters Two new per-stack adapters on the #81 interface, dependency-free (anchor + #region markers, same approach as tanstack — no AST parser, keeping dependencies:{}). - Express: detect (express dep + an `= express()` site), scaffold the generic guard, and wire `app.use(patchstackMiddleware)` right after the app is created (import + region-marked insert, idempotent). verify() checks the guard is scaffolded + the middleware is wired. - Next.js: detect (next dep); scaffold `middleware.ts` (+ co-located patchstack.rules.json) from a new template running the request-phase guard as edge middleware. An EXISTING middleware is never overwritten — we scaffold the rules and print a plan instead. verify() checks the managed middleware + rules are present. - Registered in the orchestrator (tanstack → next → express → generic fallback); AGENT-INSTALL lists the newly auto-wired stacks. +4 tests. 451 tests pass, typecheck + build clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * feat(protect): SvelteKit, Astro, Fastify adapters Three more per-stack adapters (Arcjet-parity for the JS frameworks, minus NestJS/Python), dependency-free — same anchor + #region approach, no AST parser, dependencies:{} unchanged. - SvelteKit + Astro: seam-file-is-the-guard. New shared `seam.ts` (wireSeam/verifySeam) scaffolds the framework's server hook from a template (`src/hooks.server.ts` → handle, `src/middleware.ts` → onRequest) + co-located patchstack.rules.json. An EXISTING hook is never overwritten — scaffold rules + print a compose-with-sequence() plan instead. - Fastify: register-into-app (like express). scaffoldGeneric now takes a guard-template arg so the Fastify plugin (builds a Request from the parsed fastify request → fetchGuard) lands as the guard; wire `app.register(patchstackFastify)` after the fastify() instance. - Registered most-specific-first (tanstack → next → sveltekit → astro → fastify → express → generic). - AGENT-INSTALL lists the newly auto-wired stacks. +5 tests. 456 pass, typecheck + build clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Foundation for the "two-track, never-manual" install direction — reorganizes
patchstack-connect protectaround a per-stack adapter interface.src/protect/install/—index.ts(orchestrator + registry),types.ts(Adapter={ name, label, detect, wire }),util.ts(sharedread/log/templatesDir),adapters/tanstack-supabase.ts(today's TanStack Start + Supabase logic, moved verbatim — scaffold / bake UUID / patch client + start / reconcile blocks).runProtectnow returns a structuredProtectResult—{ status: 'wired', adapter, changed }or{ status: 'unsupported', supported }.unsupported— the seam the agent-fallback track will hook into.install.ts;cli.ts+ tests repointed. Templates unchanged.Behaviorally identical for the supported stack (existing install tests all pass); +2 tests for the new result contract + escalation. 443 pass, typecheck + build clean.
Adding a new builder later = drop a file in
adapters/and register it. AST-basedwire()and the agent-assisted fallback for unmatched stacks build on this.🤖 Generated with Claude Code